import { UDC_OPEN_SDK } from "./impl";
if (!window.__UDC_OPEN_SDK__) {
    window.__UDC_OPEN_SDK__ = {
        default: UDC_OPEN_SDK,
    };
}
/** 注册 UDC 运行时 SDK
 * @example
 * ```
 * import { setUdcSdk } from '@seeyon/udc-sdk';
 *
 * setUdcSdk('2.7', {
 *   getUdcAppInfo: () => {},
 *   // ...
 * });
 * ```
 */
export const registerUdcSdk = (version, sdk) => {
    window.__UDC_OPEN_SDK__[version] = sdk;
};
export const getUdcSdk = (version) => {
    // TODO: semver match?
    let sdk = window.__UDC_OPEN_SDK__["default"];
    ;
    if (version in window.__UDC_OPEN_SDK__) {
        sdk = window.__UDC_OPEN_SDK__[version];
    }
    return sdk;
};
/**设置SDK信息 */
export const setSdkBaseInfo = (version, baseInfo) => {
    const sdk = getUdcSdk(version);
    sdk.baseInfo = baseInfo;
};
export const ready = (config, callback) => {
    const { mode, version } = config;
    if (mode !== 'iframe') {
        console.error('SDK当前仅支持iframe模式');
        return;
    }
    setSdkBaseInfo(version, {
        tenant: config.tenant
    });
    const UdcSdkForIframe = UDC_OPEN_SDK.getUdcSdkForIframe();
    UdcSdkForIframe.ready(callback);
};
